package io.github.wslxm.springbootplus2.manage.sys.controller;

import io.github.wslxm.springbootplus2.core.base.controller.BaseController;
import io.github.wslxm.springbootplus2.core.base.model.BasePage;
import io.github.wslxm.springbootplus2.core.constant.BaseConstant;
import io.github.wslxm.springbootplus2.core.result.Result;
import io.github.wslxm.springbootplus2.manage.sys.model.dto.SysMsgDTO;
import io.github.wslxm.springbootplus2.manage.sys.model.query.SysMsgQuery;
import io.github.wslxm.springbootplus2.manage.sys.model.vo.SysMsgVO;
import io.github.wslxm.springbootplus2.manage.sys.model.vo.next.SysMsgFindAllNumVO;
import io.github.wslxm.springbootplus2.manage.sys.service.SysMsgService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 订单-->及时消息通知表
 * <p>
 *  ::本代码由[兮家小二]提供的代码生成器生成,如有问题,请手动修改 ::作者CSDN:https://blog.csdn.net/qq_41463655 
 * </p>
 * @author wangsong
 * @email 1720696548@qq.com
 * @date 2020-09-23 10:40:23
 */
@RestController
@RequestMapping(BaseConstant.Uri.API_ADMIN + "/sys/msg")
@Tag( name = "base--sys--消息通知")
public class SysMsgController extends BaseController<SysMsgService> {


    @GetMapping(value = "/findPage")
    @Operation(summary = "列表查询")
    public Result<BasePage<SysMsgVO>> findPage(@ModelAttribute @Validated SysMsgQuery query) {
        return Result.success(baseService.findPage(query));
    }


    @PostMapping
    @Operation(summary = "添加/发送消息")
    public Result<String> insert(@RequestBody @Validated SysMsgDTO dto) {
        dto.setIsWebsocket(true);
        return Result.success(baseService.insert(dto));
    }


    @PutMapping(value = "/{id}/read")
    @Operation(summary = "消息修改为已读")
    public Result<Boolean> updRead(@PathVariable String id) {
        Result<Boolean> result = Result.successUpdate(baseService.updRead(id));
        result.setMsg("已读成功");
        return result;
    }


    @Operation(summary = "查询未读数量(当前登录用户)")
    @GetMapping(value = "/findUnreadNum")
    public Result<Long> findUnreadNum() {
        return Result.successFind(baseService.findUnreadNum());
    }


    @Operation(summary = "查询全部/已读/未读数量(当前登录用户)")
    @GetMapping(value = "/findAllNum")
    public Result<SysMsgFindAllNumVO> findAllNum() {
        return Result.successFind(baseService.findAllNum());
    }
}
